
--获取通关妖气发现时，纸片人的宝箱
function findReward () 
  printLog("开始查找纸片人宝箱");
  
  local shouldFind = true;
  
  while shouldFind do
    
    local x, y = findMultiColorInRegionFuzzy(0xb2451f,"-24|-21|0xfff4d4,-1|-21|0xfff4d4,23|-16|0xfff4d4,-20|13|0xfff4d4,-1|15|0xfff4d4,18|12|0xfff4d4", 95,590,543,1646,1225);
    if x ~= -1 then  --如果找到符合条件的点
      tap(x, y);
      mSleep(1000);
      tap(1888, 888);
      mSleep(1000);
      
      printLog("找到纸片人宝箱");
      
      --需要找下一个宝箱
      shouldFind = true;
    else
      shouldFind = false;
    end
  end
  
  
end

--在探索页面， 找到对应的章节并进入
function findChapter (chapter)
  printLog("妖怪发现 需要找到的章节是："..chapter);
  --识别区域
  local reactX0 = 1902;
  local reactY0 = 260;
  local reactX1 = 2162;
  local reactY1 = 1118;
  local degree = 95;
  
  local currentChapter = "未知";
  
  local x1, y1 = findMultiColorInRegionFuzzy(0xf8f3e0,"-19|3|0xf8f3e0,18|1|0xf8f3e0,-58|-16|0xf8f3e0,45|-15|0xf8f3e0,-2|-8|0x3e2312,-2|9|0x3f2311", degree, reactX0, reactY0, reactX1, reactY1);
  if x1 > -1 then
    currentChapter = "第一章";
    printLog("找到："..currentChapter.."  位置是：x = "..x1.." y = "..y1);
    if currentChapter == chapter then
      tap(x1,y1);
      return;
    end
  end
  
  
  local	x2, y2 = findMultiColorInRegionFuzzy(0xe3decc,"15|-1|0xd3cdbc,-10|25|0xeae4d2,26|24|0xede8d5,53|-10|0xd9d3c2,45|-5|0xc7c1b0,65|-7|0xe6e0ce", degree, reactX0, reactY0, reactX1, reactY1);
  if x2 > -1 then
    currentChapter = "第二章";
    printLog("找到："..currentChapter.."  位置是：x = "..x2.." y = "..y2);
    if currentChapter == chapter then
      tap(x2,y2);
      return;
    end
  end
  
  
  local x3, y3 = findMultiColorInRegionFuzzy(0xf8f3e0,"-5|-14|0xf8f3e0,6|-15|0xf8f3e0,-14|16|0xf8f3e0,18|15|0xf8f3e0,1|7|0x281a0f,1|-7|0x22180f,-55|-19|0xf8f3e0,48|-19|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x3 > -1 then
    currentChapter = "第三章";
    printLog("找到："..currentChapter.."  位置是：x = "..x3.." y = "..y3);
    
    if currentChapter == chapter then
      tap(x3,y3);
      return;
    end
  end
  
  
  local x4, y4 = findMultiColorInRegionFuzzy(0xf8f3e0,"0|8|0xf8f3e0,4|22|0xf8f3e0,16|21|0xf8f3e0,26|23|0xf8f3e0,34|6|0xf8f3e0,34|-2|0xf8f3e0,13|-2|0xf8f3e0,-40|-11|0xf8f3e0,60|-9|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x4 > -1 then
    currentChapter = "第四章";
    printLog("找到："..currentChapter.."  位置是：x = "..x4.." y = "..y4);
    
    if currentChapter == chapter then
      tap(x4,y4);
      return;
    end
  end
  
  
  local x5, y5 = findMultiColorInRegionFuzzy(0xf8f3e0,"10|-14|0xf8f3e0,-4|-13|0xf8f3e0,-14|19|0xf8f3e0,20|18|0xf8f3e0,9|7|0xf8f3e0,-54|-18|0xf8f3e0,49|-18|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  
  if x5 > -1 then
    currentChapter = "第五章";
    printLog("找到："..currentChapter.."  位置是：x = "..x5.." y = "..y5);
    if currentChapter == chapter then
      tap(x5, y5);
      return;
    end
  end
  
  local x6, y6 = findMultiColorInRegionFuzzy(0xf8f3e0,"-17|3|0xf8f3e0,17|-1|0xf8f3e0,-3|-9|0xf8f3e0,9|14|0xf8f3e0,13|22|0xf8f3e0,-56|-14|0xf8f3e0,44|-11|0xf8f3e0,0|20|0x3d2211", degree, reactX0, reactY0, reactX1, reactY1);
  if x6 > -1 then
    currentChapter = "第六章";
    printLog("找到："..currentChapter.."  位置是：x = "..x6.." y = "..y6);
    
    if currentChapter == chapter then
      tap(x6,y6);
      return;
    end
  end
  
  local x7, y7 = findMultiColorInRegionFuzzy(0xf8f3e0,"-1|-14|0xf8f3e0,-15|5|0xf8f3e0,18|-3|0xf8f3e0,3|15|0xf8f3e0,12|15|0xf8f3e0,-16|-1|0x24190f,-55|-19|0xf8f3e0,45|-17|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x7 > -1 then
    currentChapter = "第七章";
    printLog("找到："..currentChapter.."  位置是：x = "..x7.." y = "..y7);
    
    if currentChapter == chapter then
      tap(x7,y7);
      return;
    end
  end
  
  
  local x8, y8 = findMultiColorInRegionFuzzy(0xf8f3e0,"-2|3|0xf8f3e0,28|11|0xf8f3e0,22|5|0xf8f3e0,15|-5|0xf8f3e0,7|9|0x3f2311,-45|-17|0xf8f3e0,55|-15|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x8 > -1 then
    currentChapter = "第八章";
    printLog("找到："..currentChapter.."  位置是：x = "..x8.." y = "..y8);
    
    if currentChapter == chapter then
      tap(x8,y8);
      return;
    end
  end
  
  local x9, y9 = findMultiColorInRegionFuzzy(0xf8f3e0,"6|-10|0xf8f3e0,-6|0|0xf8f3e0,0|2|0xf8f3e0,16|-6|0xf8f3e0,11|4|0xf8f3e0,15|22|0xf8f3e0,28|20|0xf8f3e0,-48|-16|0xf8f3e0,52|-14|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x9 > -1 then
    currentChapter = "第九章";
    printLog("找到："..currentChapter.."  位置是：x = "..x9.." y = "..y9);
    
    if currentChapter == chapter then
      tap(x9,y9);
      return;
    end
  end
  
  
  local x10, y10 = findMultiColorInRegionFuzzy(0xf8f3e0,"0|-14|0xf8f3e0,0|17|0xf8f3e0,-16|3|0xf8f3e0,4|-1|0xf8f3e0,17|23|0x3c2111,-20|21|0x3d2111,-14|-15|0x412512,-57|-16|0xf8f3e0,43|-15|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x10 > -1 then
    currentChapter = "第十章";
    printLog("找到："..currentChapter.."  位置是：x = "..x10.." y = "..y10);
    
    if currentChapter == chapter then
      tap(x10,y10);
      return;
    end
  end
  
  
  local x11, y11 = findMultiColorInRegionFuzzy(0xf8f3e0,"0|-14|0xf8f3e0,-16|3|0xf8f3e0,28|2|0xf8f3e0,48|0|0xf8f3e0,63|-1|0xf8f3e0,46|-15|0x412412,46|14|0x3e2311,-57|-16|0xf8f3e0,89|-15|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x11 > -1 then
    currentChapter = "第十一章";
    printLog("找到："..currentChapter.."  位置是：x = "..x11.." y = "..y11);
    
    if currentChapter == chapter then
      tap(x11,y11);
      return;
    end
  end
  
  local x12, y12 = findMultiColorInRegionFuzzy(0xf8f3e0,"62|-9|0x402512,0|-15|0xf8f3e0,-17|2|0xf8f3e0,-1|13|0xf8f3e0,41|-9|0xf8f3e0,51|-11|0xf8f3e0,32|15|0xf8f3e0,60|14|0xf8f3e0,-57|-17|0xf8f3e0,89|-15|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x12 > -1 then
    currentChapter = "第十二章";
    printLog("找到："..currentChapter.."  位置是：x = "..x12.." y = "..y12);
    
    if currentChapter == chapter then
      tap(x12,y12);
      return;
    end
  end
  
  local x13, y13 = findMultiColorInRegionFuzzy(0xf8f3e0,"0|-13|0xf8f3e0,-17|3|0xf8f3e0,40|-10|0xf8f3e0,50|-11|0xf8f3e0,42|4|0xf8f3e0,48|2|0xf8f3e0,31|20|0xf8f3e0,61|18|0xf8f3e0,45|-4|0x22180f,-57|-16|0xf8f3e0,89|-14|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x13 > -1 then
    currentChapter = "第十三章";
    printLog("找到："..currentChapter.."  位置是：x = "..x13.." y = "..y13);
    
    if currentChapter == chapter then
      tap(x13,y13);
      return;
    end
  end
  
  local x14, y14 = findMultiColorInRegionFuzzy(0xf8f3e0,"0|-15|0xf8f3e0,-16|2|0xf8f3e0,30|-7|0xf8f3e0,29|1|0xf8f3e0,46|14|0xf8f3e0,57|16|0xf8f3e0,63|1|0xf8f3e0,63|-9|0xf8f3e0,-57|-17|0xf8f3e0,89|-15|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x14 > -1 then
    currentChapter = "第十四章";
    printLog("找到："..currentChapter.."  位置是：x = "..x14.." y = "..y14);
    
    if currentChapter == chapter then
      tap(x14,y14);
      return;
    end
  end
  
  
  local x15, y15 = findMultiColorInRegionFuzzy(0xf8f3e0,"0|-14|0xf8f3e0,-16|2|0xf8f3e0,40|-11|0xf8f3e0,53|-13|0xf8f3e0,39|3|0xf8f3e0,53|3|0xf8f3e0,30|20|0xf8f3e0,63|19|0xf8f3e0,52|9|0xf8f3e0,45|-2|0xf8f3e0,52|9|0xf8f3e0,-57|-17|0xf8f3e0,90|-15|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x15 > -1 then
    currentChapter = "第十五章";
    printLog("找到："..currentChapter.."  位置是：x = "..x15.." y = "..y15);
    
    if currentChapter == chapter then
      tap(x15,y15);
      return;
    end
  end
  
  local x16, y16 = findMultiColorInRegionFuzzy(0xf8f3e0,"0|-13|0xf8f3e0,-16|2|0xf8f3e0,29|-1|0xf8f3e0,43|-12|0xf8f3e0,62|-5|0xf8f3e0,54|11|0xf8f3e0,58|18|0xf8f3e0,47|21|0x3c2110,-57|-17|0xf8f3e0,89|-15|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x16 > -1 then
    currentChapter = "第十六章";
    printLog("找到："..currentChapter.."  位置是：x = "..x16.." y = "..y16);
    
    if currentChapter == chapter then
      tap(x16,y16);
      return;
      
    end
  end
  
  
  local x17, y17 = findMultiColorInRegionFuzzy(0xf8f3e0,"0|-14|0xf8f3e0,-16|2|0xf8f3e0,30|6|0xf8f3e0,45|-10|0xf8f3e0,45|7|0xf8f3e0,49|18|0xf8f3e0,56|17|0xf8f3e0,63|-1|0xf8f3e0,-57|-17|0xf8f3e0,89|-15|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x17 > -1 then
    currentChapter = "第十七章";
    printLog("找到："..currentChapter.."  位置是：x = "..x17.." y = "..y17);
    
    if currentChapter == chapter then
      tap(x17,y17);
      return;
      
    end
  end
  
  local x18, y18 = findMultiColorInRegionFuzzy(0xf8f3e0,"0|-13|0xf8f3e0,-16|2|0xf8f3e0,34|1|0xf8f3e0,51|-2|0xf8f3e0,60|10|0xf8f3e0,44|6|0x3f2411,41|14|0x3e2311,-57|-17|0xf8f3e0,89|-15|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x18 > -1 then
    currentChapter = "第十八章";
    printLog("找到："..currentChapter.."  位置是：x = "..x18.." y = "..y18);
    
    if currentChapter == chapter then
      tap(x18,y18);
      return;
    end
  end
  
  local x19, y19 = findMultiColorInRegionFuzzy(0xf8f3e0,"43|19|0xf8f3e0,57|16|0xf8f3e0,57|4|0xf8f3e0,57|31|0xf8f3e0,89|15|0xf8f3e0,99|9|0xf8f3e0,98|22|0x22180f,120|37|0xf8f3e0,150|1|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x19 > -1 then
    currentChapter = "第十九章";
    printLog("找到："..currentChapter.."  位置是：x = "..x19.." y = "..y19);
    
    if currentChapter == chapter then
      tap(x19,y19);
      return;
    end
  end
  
  local x20, y20 = findMultiColorInRegionFuzzy(0xf8f3e0,"51|8|0xf8f3e0,42|32|0xf8f3e0,88|19|0xf8f3e0,104|4|0xf8f3e0,104|31|0xf8f3e0,114|36|0x3d2110,104|16|0xf8f3e0,149|1|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x20 > -1 then
    currentChapter = "第二十章";
    printLog("找到："..currentChapter.."  位置是：x = "..x20.." y = "..y20);
    
    if currentChapter == chapter then
      tap(x20,y20);
      return;
    end
  end
  
  local x21, y21 = findMultiColorInRegionFuzzy(0xf8f3e0,"51|8|0xf8f3e0,42|32|0xf8f3e0,88|19|0xf8f3e0,104|16|0xf8f3e0,104|4|0xf8f3e0,133|18|0xf8f3e0,149|1|0x412512,167|16|0xf8f3e0,196|1|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x21 > -1 then
    currentChapter = "第二十一章";
    printLog("找到："..currentChapter.."  位置是：x = "..x21.." y = "..y21);
    
    if currentChapter == chapter then
      tap(x21,y21);
      return;
    end
  end
  
  local x22, y22 = findMultiColorInRegionFuzzy(0xf8f3e0,"51|8|0xf8f3e0,43|32|0xf8f3e0,87|19|0xf8f3e0,103|3|0xf8f3e0,103|33|0xf8f3e0,145|8|0xf8f3e0,136|33|0xf8f3e0,150|19|0x3f2411,193|2|0xf8f3e0", degree, reactX0, reactY0, reactX1, reactY1);
  if x19 > -1 then
    currentChapter = "第二十二章";
    printLog("找到："..currentChapter.."  位置是：x = "..x22.." y = "..y22);
    
    if currentChapter == chapter then
      tap(x22,y22);
      return;
    end
  end
  
  
  printLog("识别出来的章节文字是："..currentChapter);
  local findChapterNumber = covertChapterToNumber(currentChapter);
  local chapterNumber = covertChapterToNumber(chapter);
  if findChapterNumber > chapterNumber then
    --下拉
    swip(2031,300, 2043,1000);
  else
    --上拉
    swip(2043,1000,2031,300);
  end
  
  mSleep(500);
  findChapter(chapter);
end


--查找指定业原火章节
function findYeyuanhuoChapter (chapter)
  
  if chapter == "贪之阵" then
    return 668,308;
  elseif chapter == "嗔之阵" then
    return 647,476;
  elseif chapter == "痴之阵" then
    return 670,644;
  end
  
  return -1, -1;
end

--查找指定八岐大蛇章节
function findSnakeChapter (chapter)
  
  mSleep(1000);
  printLog("八岐大蛇 或 觉醒 需要找到的章节是："..chapter);
  
  --上拉 让最后一行为 十层
  swip(690,681, 666,246);
  mSleep(1000);
  --10~7层
  if chapter == "拾层" then
    return 705,661;
    
  elseif chapter == "玖层" then
    return 696,528;
    
  elseif chapter == "捌层" then
    return 702,402;
    
  elseif chapter == "柒层" then
    return 701,272;
  end
  
  --下拉 让最后一行为 陆层
  swip(699,231, 705,423);
  mSleep(1000);
  if chapter == "陆层" then
    return 700,662;
    
  elseif chapter == "伍层" then
    return 702,536;
    
  elseif chapter == "肆层" then
    return 705,409;
    
  elseif chapter == "叁层" then
    return 702,278;
    
  end
  
  --下拉 让第一行为第一层
  swip(699,231, 705,423);
  mSleep(1000);
  
  if chapter == "贰层" then
    return 697,419;
    
  elseif chapter == "一层" then
    return 698,295;
    
  end
  
  return -1, -1;
end


function findTaskMonster ()
  
  local taskX, taskY = -1, -1;
  
  keepScreen(true);
  
  --上弧度
  taskX, taskY = findMultiColorInRegionFuzzy(0x444e83,"-7|-62|0xffffee,8|-64|0xfffff1,20|-63|0xfffff2,36|-57|0xfffff1", 95, 1, 100, 2200,1042);
  
    --下弧度
  if taskX == -1 then
    taskX, taskY = findMultiColorInRegionFuzzy(0x444e83,"-12|61|0xffffe7,0|64|0xffffe7,17|64|0xffffe5,32|60|0xffffe4", 95, 1, 100, 2200,1042);
  end
  
  --左
  if taskX == -1 then
    taskX, taskY = findMultiColorInRegionFuzzy(0x444e83,"-46|-21|0xfffbe3,-48|1|0xffffea,-47|16|0xffffeb,-43|28|0xffffea", 95, 1, 100, 2200,1042);
  end
  
  --右
  if taskX == -1 then
    taskX, taskY = findMultiColorInRegionFuzzy(0x444e83,"75|-26|0xfffff3,78|-17|0xffffeb,79|3|0xffffec,75|20|0xffffe9", 95, 1, 100, 2200,1042);
  end
  
  --右上
  if taskX == -1 then
    taskX, taskY = findMultiColorInRegionFuzzy(0x444e83,"36|-64|0xffffec,51|-55|0xffffea,62|-44|0xfffffb,71|-31|0xffffea", 95, 1, 100, 2200,1042);
  end
  
  --左下
  if taskX == -1 then
    taskX, taskY = findMultiColorInRegionFuzzy(0x444e83,"-45|29|0xffffe8,-39|37|0xffffff,-32|45|0xfffde3,-23|52|0xfffffb", 95, 1, 100, 2200,1042);
  end
  
  --左上
  if taskX == -1 then
    taskX, taskY = findMultiColorInRegionFuzzy(0x444e83,"-37|-46|0xfffff3,-24|-59|0xffffec,-10|-63|0xffffef,4|-66|0xffffee", 95, 1, 100, 2200,1042);
  end
  
  --右下
  if taskX == -1 then
    taskX, taskY = findMultiColorInRegionFuzzy(0x444e83,"17|62|0xffffe5,38|55|0xffffe5,52|48|0xffffdb,59|42|0xffffee", 95, 1, 100, 2200,1042);
  end
  
  keepScreen(false);
  
  if taskX > -1 then
    return taskX, taskY;
  else
    return -1, -1;
  end
end

function findTaskBossMonster ()
  return findTaskMonster();
end



--找攻击标志
function findMonster (attackType, attackTypeBoss)
  printLog("寻找攻击目标："..attackType);
  
  for tmpi=1,10 do
    
    --是否打boss 优先打boss
    if attackTypeBoss then
      
      --任务boss
      local taskBossX0, taskBossY0 = findMultiColorInRegionFuzzy(0x455180,"-5|17|0xb93638,20|19|0xe5cec0,-20|-21|0x221108,30|10|0xf0e6e0,-23|26|0xe6949b", 95, 1, 100, 2200,1042);
      if taskBossX0 > -1 then
        printLog("打任务boss");
        return taskBossX0, taskBossY0;
      end
      
      --普通boss
      local bossX, bossY = findMultiColorInRegionFuzzy(0x452b57,"-51|-22|0xcb3b3c,52|-38|0xcd3131,2|29|0xfffffc,52|50|0xd4a344,-6|58|0xeca6ad,10|-55|0xeeb3b9", 95, 1, 100, 2200,1042)
      if bossX > -1 then
        printLog("打普通boss");
        return bossX, bossY;
      end
    end
    
    --任务小怪
    local taskX, taskY = findTaskMonster();
    if taskX > -1 then
      printLog("打任务怪 x = "..taskX.."  y = "..taskY);
      return taskX, taskY;
    elseif attackType == "打任务怪" then
      return -1, -1;
    end
    
    --找到所有的攻击标志
    --local point = findMultiColorInRegionFuzzyExt(0x8d8eba,"41|0|0xcf7c80,-10|33|0xec9fa8,41|-30|0x9e7a47,-47|-52|0xcd9e46,22|20|0x232755", 95, 1,479,2200,1042);
    local point = findMultiColorInRegionFuzzyExt(0x8d8eba,"5|-88|0x704621,1|60|0x734922,81|-13|0x29160b,30|-42|0xf3d363,-28|35|0xdc757b,41|-6|0xde979e,27|21|0x242652", 95, 1,100,2200,1042);
    
    printLog("所有的攻击标志:");
    printTable(point);
    
    if #point ~= 0 then  --如果找到符合条件的点
      for var = 1,#point do
        local x, y = point[var].x, point[var].y;
        
        --根据找到的攻击， 得到下方一个区域，用来判断是哪一种类型的妖怪
        local x1,y1, x2,y2 =  x - 120, y + 100, x + 120, _height;
        
        if attackType == "打全部" then
          printLog("打全部");
          return x, y;
        elseif attackType == "打经验怪" then
          local x0, y0 = findMultiColorInRegionFuzzy(0xd07a17,"9|-1|0xddcca2,-3|11|0xf0bb03", 95, x1, y1, x2, y2);
          if x0 ~= -1 and y0 ~= -1 then  --如果找到符合条件的点
            printLog("打经验怪");
            return x, y;
          end
        elseif attackType == "打金钱怪" then
          local x0, y0 = findMultiColorInRegionFuzzy(0xe7cc0c,"5|-9|0xf0b409,-8|-36|0xd9cd84,-6|-32|0xd5c77e", 95, x1, y1, x2, y2);
          if x0 ~= -1 and y0 ~= -1 then  --如果找到符合条件的点
            printLog("打金钱怪");
            return x, y;
          end
          
        elseif attackType == "打经验和金钱怪" then
          local x0, y0 = findMultiColorInRegionFuzzy(0xd07a17,"9|-1|0xddcca2,-3|11|0xf0bb03", 95, x1, y1, x2, y2);
          if x0 ~= -1 and y0 ~= -1 then  --如果找到符合条件的点
            printLog("打经验怪");
            return x, y;
          end
          
          local x0, y0 = findMultiColorInRegionFuzzy(0xe7cc0c,"5|-9|0xf0b409,-8|-36|0xd9cd84,-6|-32|0xd5c77e", 95, x1, y1, x2, y2);
          if x0 ~= -1 and y0 ~= -1 then  --如果找到符合条件的点
            printLog("打金钱怪");
            return x, y;
          end				
        end
      end
    else
      return -1, -1;
    end
    
    mSleep(100);
  end
  
  return -1, -1;
end



--是否是指定的好友
function findTargetFriend ()
  --表示选择列表中的第一个
  if friendKind == 0 then
    return 849,360;
    
    --系统内置
  elseif friendKind == 1 then
    
    
    local lines = {};
    --黎白南元  0x2d2925-0x555555
    lines[1] = "0080102604F09E7FCFFBFF77EC7D808000080300E0781E3FFFFF87C0F01803F87F07E0C0000000000000000000000000000000000000010020040080000200C0783F7FFFFDF1BC330600C0180700E01C0780F00E00C0180300200000000000000000000000000000000000000000000000000040180300600E03FFFFFFFFC7F80F01C0380700E0180000000000000000000000000000000000000000000000000000000000000000180300E0180300E01C0300600C0380700E01C000000400801002$黎白南元$3.7.1387$34";
    --黎白南唐
    lines[2] = "0040081302704E3FC7F9FF3BE63CC00000040180703C0F0FFDFF83E0780C01F83F03E06000000000000000000000000000000000000000000000000000000040381F3FEFFCF89E11820040080300600C0380700600400801000000000000000000000000000000000000000000000000000000200C0180300701EFFDFFBFE3FC0780E01C0380700C000000000000000000000000000000000000000000000000000000000001807C0F81F0180600C0180308738FF9F7FE7FC1C8390621C4388700E0080$黎白南唐$3.5.1527$35";
    
    --加载自定义字库
    local dic = createOcrDict(lines);
    
    --向下最多滚动3次
    for tmpi=1,3 do
      local point = ocrText(dic,607,274,1600,913, {"0x2d2925-0x555555"}, 93,1,0);
      
      printLog("识别好友名字");
      printTable(point);
      
      if #point ~= 0 then  --如果找到符合条件的点
        for var = 1,#point do
          if point[var].text == "黎白南元" or point[var].text == "黎白南唐" then
            local x, y = point[var].x, point[var].y;
            return x, y;
          end
        end
      else
        swip(1000, 800, 1000, 300);
      end
    end
    
  end
  
  return -1, -1;
end



--是否是指定的好友
function findTargetFriend2 ()
  
  --向下最多滚动3次
  local x, y = -1, -1;
  
  for tmpi=1,4 do
    
    if friendKind == 0 then
      x, y = findMultiColorInRegionFuzzy(0x000000,"88|61|0xffffff", 95, 0, 0, 1919, 1079);
      
    elseif friendKind == 1 then
      x, y = findMultiColorInRegionFuzzy(0x000000,"88|61|0xffffff", 95, 0, 0, 1919, 1079);
      
      
    elseif friendKind == 2 then
      x, y = findMultiColorInRegionFuzzy(0x000000,"88|61|0xffffff", 95, 0, 0, 1919, 1079);
      
    elseif friendKind == 3 then
      x, y = findMultiColorInRegionFuzzy(0x000000,"88|61|0xffffff", 95, 0, 0, 1919, 1079);
      
    elseif friendKind == 4 then	
      x, y = findMultiColorInRegionFuzzy(0x000000,"88|61|0xffffff", 95, 0, 0, 1919, 1079);
      
    end
    
    if x > -1 then
      return x, y;
    else
      swip(1000, 800, 1000, 300);
    end
  end
  
  return -1, -1;
end


--查询有0-5个勋章的位置
function findHonor (number, reactX0, reactY0, reactX1, reactY1)
  local  x, y = -1, -1;
  local point = {};
  if number == 0 then
    point = findMultiColorInRegionFuzzyExt(0xd5c8b8,"68|0|0xd5c8b8,136|0|0xd5c8b8,204|0|0xd5c8b8,272|0|0xd5c8b8,340|0|0xd5c8b8,0|82|0x9c8976,-149|0|0x9c8976", 99, reactX0, reactY0, reactX1, reactY1);
    
  elseif number == 1 then
    point = findMultiColorInRegionFuzzyExt(0xd5c8b8,"68|0|0x914e43,136|0|0xd5c8b8,204|0|0xd5c8b8,272|0|0xd5c8b8,340|0|0xd5c8b8,0|82|0x9c8976,-149|0|0x9c8976", 99, reactX0, reactY0, reactX1, reactY1);
    
  elseif number == 2 then
    point = findMultiColorInRegionFuzzyExt(0xd5c8b8,"68|0|0x914e43,136|0|0x914e43,204|0|0xd5c8b8,272|0|0xd5c8b8,340|0|0xd5c8b8,0|82|0x9c8976,-149|0|0x9c8976", 99, reactX0, reactY0, reactX1, reactY1);
    
  elseif number == 3 then
    point = findMultiColorInRegionFuzzyExt(0xd5c8b8,"68|0|0x914e43,136|0|0x914e43,204|0|0x914e43,272|0|0xd5c8b8,340|0|0xd5c8b8,0|82|0x9c8976,-149|0|0x9c8976", 99, reactX0, reactY0, reactX1, reactY1);
    
  elseif number == 4 then            
    point = findMultiColorInRegionFuzzyExt(0xd5c8b8,"68|0|0x914e43,136|0|0x914e43,204|0|0x914e43,272|0|0x914e43,340|0|0xd5c8b8,0|82|0x9c8976,-149|0|0x9c8976", 99, reactX0, reactY0, reactX1, reactY1);
    
  elseif number == 5 then			--五个勋章的属于特殊情况 打过并且失败的情况下无法识别出来，不过对运行没有影响					
    point = findMultiColorInRegionFuzzyExt(0xd5c8b8,"68|0|0x914e43,136|0|0x914e43,204|0|0x914e43,272|0|0x914e43,340|0|0x914e43,0|82|0x9c8976,-149|0|0x9c8976", 99, reactX0, reactY0, reactX1, reactY1);
    
  end
  
  printTable(point);
  
  if #point ~= 0 then  --如果找到符合条件的点
    for var = 1,#point do
      local tempX, tempY = point[var].x, point[var].y;
      if unActtacked(tempX, tempY) then
        return tempX, tempY;
      end
    end
  end
  
  return -1, -1;
end

function unActtacked (x, y)
  if x > -1 then
    
    --生成新的查询区域
    local x1 = x + 312;
    local y1 = y - 112;
    local x2 = x + 403;
    local y2 = y - 49;
    
    local x0, y0 = findColorInRegionFuzzy(0x3d0c07, 99, x1, y1, x2, y2);
    if x0 == -1 then
      return true;
    else
      return false;
    end
  end
  
  return false;
end

--结界突破 攻击按钮 组队按钮
function findButton (buttonName)
  local lines = {};
  if buttonName == "组队" then
    lines[1] = "00601C1F8FEFF9FE3F03C000200C018010020000000000007C0F81F03E0700C0180300601C0380E01E03C07F07E0FC0F808000000000000000000000000000000000000000401FF1FE3FC7F8E0380700C0BCF7FCFF0FC1E03802000000000000000000000005FFBFF7FE7E0400$组队$6.18.1210$41";
    
  elseif buttonName == "攻击" then
    lines[1] = "0060FDFFFFF7F0F808000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003807FFFFFFFFFF8010000040080100200C0180300600C$攻击$25.11.1138$45";
    
  elseif buttonName == "刷新" then
    lines[1] = "0200FC1F83F0300601C0380600C0180700E01FC3F87F07C0F0080000000000000000000000000000000001803FC7FCFF9FF3E00000000000000000000000000000000000000000100600C0180700E0180360EE1CE31F61EC03C0780E01C03800000000000004008010020040180300E0380701C0781F07C078070040$刷新$10.4.1316$47";
    
  elseif buttonName == "离开队伍" then
    lines[1] = "00200C0180300600C0180700E01C03E07E0FE1FE73FE7FC67C0780F03E07C0F01E0380700E03C0780F01E03C03800000000000000000000000000000000000000000000000000000000000000200401C0380700E01C0780F01E03C0F81E03C0780F03F07E0FC1F83F0FA1F03C0780F01E01C000000000000000000000000000000000000000000000000000000000F01E03C0780F01C0700E03C07E0FC0F81F03C03000000000000000000000001F83F07E0FC0E000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001C078FF1FE3F03C02000000000000000004008010020040180300601C0380700E01C0780F01E03C07006$离开队伍$2.8.2553$49";
    
  elseif buttonName == "开始战斗" then
    lines[1] = "00401C0380700E01C0780F03E07C0F81F03E07C0F83F07E0FC3F87F0FE1FC3F87C1F83F07E07C0F0000000000000000000000000000000000000000000000000000000000000000000000000001FE7FCFF9FF3FE3F83800000000000000000000000000000000000100E3FCFF9FF1FE1FC3E07C0400000000000000000000000000000000000000000000000000000000000000000FE1FC3F87F0FE0C00000000000000000000000003007F0FFDFFBFF7FEFFC000000400E01E03C07C0FC0F81F01C000000000000000000000000000000000000000000000000000000000000000000000000000000180780700E01C0380700600000200FFFFFFFFFFF7FEFFCF80$开始战斗$9.17.3172$50";
    
  elseif buttonName == "取消" then
    lines[1] = "0200600C03F07E0FC1F83F0F01E0380700E01E07F8FF1FE7FCF21E03C078020000000000008010020040180300E01C038030060040080100000000000000000000000000000000000000000000000000000000C01C03C07C07C0F80F800000000000010060040080000000000780FFFFFFFFBFF3800000000000201C0787F07C0F80E018$取消$2.0.1388$47";	
  elseif buttonName == "个人空间" then
    lines[1] = "00200C0F83FFFDFF3FE7FC63C03C038030020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038FF0FE1FC3E01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200400801002004008010020040080300780F81F83F06F0DF19E738E01C0380701C0380700E01C0780F03E03E07C0780700E00C008000000000000000000000000000000000000000000180300200480180380780F80F008000000000000000080100700E01C0300E01C0380701C0380700E01C01FC3F87F0FE070$个人空间$16.0.1917$48";
  end
  
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  
  local point = ocrText(dic, 181,116,1996,1150, {"0x272420-0x666666"}, 95,1,0);
  
  if #point ~= 0 then  --如果找到符合条件的点
    for var = 1,#point do
      
      if point[var].text == buttonName then
        local x, y = point[var].x, point[var].y;
        return x, y;
      end
    end
  end
  return -1,-1;
end

--查找是否发现宝箱
function findTreasureBox () 
  printLog("查找是否有宝箱");
  local x, y = findMultiColorInRegionFuzzy(0xb23519,"-3|9|0xf7b515,-37|-3|0xb12919,35|2|0xb63819,10|-26|0x51292a,-15|-26|0xc04c1c,52|-24|0xbd4a1c", 95, 0, 0, 2207, 1241)
  if x > -1 then
    printLog("发现宝箱");
    return x, y;
  end
  
  return -1, -1;
end


--查找组队的分类
function findTeamSort (sortName)
  
  printLog("~~~~~开始查找组队分类："..sortName);
  local lines = {};
  --结界突破 0x292521-0x444444
  lines[1] = "00603C7F0FC1E018000000000000000000000000000000000000000200FFDFFBFF38000000000000000000000000000000000000000000000000000000000000000000000000000000000F81F81FE3BC80100200400821843187FCFF9FF23843086608C0180300400C0FFFFFFBFE3F8780E0000000000000000000000000000000000000000000000000000000000000000000000002004008010020040080300600C01803807C0DC13C0788710020040180300600C0180300601C03C07C0F80F00E01C0180000000000000000000000000000000000000000000000000000000000000000000000200400801000000000000000000000000000000000FFFFFFFFBC10000000000100200400801$结界突破$7.7.1997$48";
  
  --加载自定义字库
  local dic = createOcrDict(lines);
  
  local point = {};
  
  --查询
  for tmpi=1,2 do
    point = ocrText(dic, 288,204,553,1090, {"0x292521-0x444444"}, 95,1,0);
    printTable(point);
    if #point ~= 0 then
      if sortName == "石距" then
        return 431,788;
      elseif sortName == "年兽" then
        return 438,660;
      elseif sortName == "妖气封印" then
        return 437,281;
      elseif sortName == "经验妖怪" then	
        return 415,418;
      elseif sortName == "金币妖怪" then	
        return 428,527;
      elseif sortName == "附近妖怪" then
        return 451,913;
      end
    end
    
    --程序运行到这里，需要向上滑动
    swip(500,900, 500,300);
    mSleep(500);
  end
  
  return -1,-1;
end

--组队确认页面 查找指定最小等级
function findTargetLevel(minLevel) 
  
  local lines = {};
  --0~9  0x15120e-0x333333
  lines[1] = "0701C0380E03C1FFFFFBFF$1$0.0.109$32";
  lines[2] = "07C1F8FF1F8780E0380700E01C0380700F00F00F81FF1FE07C018$2$1.0.230$34";
  lines[3] = "0201C07C1F83E0F01C0700E01C0380700F00E05FF9FF1FE1F8$3$1.2.257$34";
  lines[4] = "00603C0F8FF3FFFFDFFBFF200$4$8.3.235$34";
  lines[5] = "7FEFFDFFBFF700E01C0380601C0380700E01C0380700600$5$3.1.268$34";
  lines[6] = "00201C0783F07C1F07C1F03C0F01E03C0F81E01C0100$6$2.3.265$34";
  lines[7] = "080180380F01E0380701C0380700E01C0700E03E3FFF7FE7FC78060$7$0.0.172$34";
  lines[8] = "07E1FCFF9C1600C0380600C0180300700E00E01F09FF1FE0FC070$8$1.1.286$34";
  lines[9] = "01E1FC7F9F83C0E0180700C0180300600E00C01C01E03F03FC1F81F$9$0.1.241$34";
  lines[10] = "00E0FC3F8FC380E0180700C0180300600E00C01C01C01F81FC1F80F$0$1.1.252$34";
  
  local dic = createOcrDict(lines);
  
  
  local result = ocrText(dic,1391,530,1461,590, {"0x15120e-0x333333"}, 95,0,0);
  
  printLog("识别出来的等级是："..result);
  
  if result == tostring(minLevel) then
    return;
  end
  
  
  --先上滑到60
  --上滑
  for tmpi=1,10 do
    swip(1400,730, 1400,370);
    mSleep(150);
  end
  
  mSleep(1500);
  
  --最多滚动60次
  for tmpi=1, 60 - minLevel do
    --上滑
    swip( 1400,560, 1400,590);
    mSleep(1500);
    
  end
  
end



--找满字
function findFullInArea(area)
  
  local x, y = findMultiColorInRegionFuzzy(0xf0ce09,"-18|6|0xffeb03,-18|-9|0xf4b611,-16|-21|0xff9d1a,-4|-19|0xffa219,4|-21|0xff9d1a,12|4|0xffe605", 95, area[1], area[2], area[3], area[4]);
  return x, y;
  
end

--找到没有满的狗粮，移动到指定位置
function moveUnfullToPoint(x, y, scrollTimes)
  
  for tmpi=1,scrollTimes do
    printLog("开始找未满的非红黑蓝蛋式神");
    --找到未满的式神
    --local point = findMultiColorInRegionFuzzyExt(0x603f20,"-15|5|0x2d170e,-16|56|0x2d170e,39|-33|0x2d170e,68|-33|0x2d170e,0|-38|0x603f20,19|-18|0x603f20", 98, 285, 884, 1681, 988)
    local point = findMultiColorInRegionFuzzyExt(0x372215,"0|2|0x27160c,-1|2|0x27160c,1|2|0x27160c,0|-39|0x372215,0|-41|0x251209,-1|-41|0x251209,1|-41|0x251209,0|-46|0xf8f1b5", 98, 285, 884, 1681, 940);
    
    printTable(point);
    if #point > 0 then
      for tmpi=1,#point do
        local newArea = {point[tmpi].x - 13, point[tmpi].y + 14, point[tmpi].x + 168, point[tmpi].y + 224 };
        
        
        --过滤已经观战或出战的式神
        keepScreen(true);
        local watchX, watchY = findMultiColorInRegionFuzzy(0x095197,"-30|26|0xa4d8ff,-34|12|0x095197,19|53|0xb3deff,0|-1|0x095197,13|7|0xbae1ff", 95, newArea[1], newArea[2], newArea[3], newArea[4]);
        local fightX, fightY = findMultiColorInRegionFuzzy(0xf87726,"-10|19|0xf87726,25|1|0xf87726,14|-20|0xffe6c6,15|26|0xffebce,-11|0|0xffe4c3,10|6|0xf87726", 95, newArea[1], newArea[2], newArea[3], newArea[4]);
        local redX, redY = findMultiColorInRegionFuzzy(0xfee6d1,"50|22|0x241d1e,-48|22|0x241d1e,65|84|0x683516,-63|89|0x6b3918,-65|82|0x683516,16|102|0xc6f6fa", 95, newArea[1], newArea[2], newArea[3], newArea[4]);
        local blackX, blackY = findMultiColorInRegionFuzzy(0xffffff,"55|16|0xffffff,64|44|0xfff2e0,-15|45|0xfff2e0,-1|68|0xbb934d,59|77|0xb88d44,98|76|0xb1873e", 95, newArea[1], newArea[2], newArea[3], newArea[4]);
        local blueX, blueY = findMultiColorInRegionFuzzy(0x3d3836,"19|57|0x79e9f3,-45|11|0x312b29,47|1|0x2d2826,-13|-47|0x4b76cd,73|-44|0x335394,-68|-44|0x355799,-73|32|0x263163", 95, newArea[1], newArea[2], newArea[3], newArea[4]);
        keepScreen(false);
        
        
        if watchX > -1 then
          printLog("找到的是观战式神，跳过");
        elseif fightX > -1 then
          printLog("找到的是出战式神，跳过");
        elseif redX > -1 then
          printLog("找到的是红蛋，跳过");
        elseif blackX > -1 then
          printLog("找到的是黑蛋，跳过");
        elseif blueX > -1 then
          printLog("找到的是蓝蛋，跳过");
        else
          printLog("找到需要升级的狗粮，开始判断星级是否满足条件。");
          
          if autoChangeStarLevel == 4 then
            --选择的是六星及以下
            swip(point[tmpi].x + 76, point[tmpi].y - 23, x , y + 200 );
            mSleep(500);
            return;					
          end
          
          --判断第6个逗号的颜色是否为黑色 true：表示5星及以下 false：表示六星及以上
          local star6Area = {point[tmpi].x + 131, point[tmpi].y + 243, point[tmpi].x + 154, point[tmpi].y + 265 };
          local star5Area = {point[tmpi].x + 106, point[tmpi].y + 243, point[tmpi].x + 130, point[tmpi].y + 265 };
          local star4Area = {point[tmpi].x + 79, point[tmpi].y + 243, point[tmpi].x + 104, point[tmpi].y + 265 };
          local star3Area = {point[tmpi].x + 54, point[tmpi].y + 243, point[tmpi].x + 79, point[tmpi].y + 265 };
          
          --判断星级
          local starArea = {};
          if autoChangeStarLevel == 0 then
            --二星
            starArea = star3Area;
          elseif  autoChangeStarLevel == 1 then
            --三星及以下
            starArea = star4Area;
          elseif  autoChangeStarLevel == 2 then
            --四星及以下
            starArea = star5Area;
          elseif  autoChangeStarLevel == 3 then
            --五星及以下
            starArea = star6Area;			
          end
          
          local starLevelX, starLevelY = findMultiColorInRegionFuzzy(0x787878,"0|-2|0x787878,0|-4|0x787878,1|-5|0x787878,3|-5|0x787878", 100, starArea[1], starArea[2], starArea[3], starArea[4]);
          if starLevelX > -1 then
            --找到的是需要的狗粮
            swip(point[tmpi].x + 76, point[tmpi].y - 23, x , y + 200 );
            mSleep(500);
            return;
          end
        end
      end
    end
    printLog("未找到可换上的式神");
    
    
    if isPage("更换式神") then
      printLog("开始滑动");
      
      --向右滑动一页
      if scrollSpeed == 0 then
        swip(1626,1018,411,1058);
        
      elseif scrollSpeed == 1 then
        --中速
        quickSwip(1626,1018,411,1058);
        quickSwip(1626,1018,411,1058);
      else 
        --快速
        quickSwip(1626,1018,411,1058);
        quickSwip(1626,1018,411,1058);
        quickSwip(1626,1018,411,1058);
      end
      --一秒钟时间等待停止滚动
      printLog("结束滑动，等待停止");
      mSleep(1000);
      
      printLog("滑动停止。");
    else
      return;
    end
  end
  
end

